package ken.app.adapter;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import ken.app.bean.QueryMemberContentBean;
import ken.app.bean.QueryMemberContentBean;
import com.she.olympic.R;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.AnimationDrawable;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

import com.she.component.adapter.GenView;
import com.she.component.adapter.GeneralAdapter;
import com.she.component.adapter.iface.IGenView;
import com.she.olympic.TreeActivity;

public class QueryMemberContentAdapter extends GeneralAdapter {
	
	static ArrayList<QueryMemberContentBean> mDataList;
	static Handler mhandler;
	static GenSelectAllListItemView mGenSelectAllView = new GenSelectAllListItemView();
	
	public QueryMemberContentAdapter(Context context, List<?> dataList ,Handler handler) {
		super(context, mGenSelectAllView);
		mDataList = (ArrayList<QueryMemberContentBean>) dataList;
		mhandler = handler;
		this.setData(mDataList);
	}
			
	public static class GenSelectAllListItemView extends GenView{
		LayoutInflater inflater;
		
		@Override
		protected View genBody(Context context, View convertView,
				final Object element, final int position) {
						
			if (inflater == null) {
				inflater = LayoutInflater.from(context);
			}
			final ViewHolder holder;
			if (convertView != null	&& convertView.getTag() instanceof ViewHolder) 
			{
				holder = (ViewHolder) convertView.getTag();
			} else 
			{
				convertView = inflater.inflate(R.layout.treesingle_row, null);
				holder = new ViewHolder();
				holder.treeSinglName = (TextView) convertView.findViewById(R.id.tree_singl_name);
				holder.treeSinglDescription = (TextView) convertView.findViewById(R.id.tree_singl_description);
				holder.treeSinglDescDate = (TextView) convertView.findViewById(R.id.tree_singl_desc_date);
				holder.treeSinglSpname = (TextView) convertView.findViewById(R.id.tree_singl_spname);

				convertView.setTag(holder);
			}
			String tempString2 = ((QueryMemberContentBean) element).getItemName();
			
			if (tempString2.length()>6) {
				holder.treeSinglName.setText(tempString2.substring(0, 6)+"...");
			}else{
				holder.treeSinglName.setText(tempString2);
			}
			
			String tempString = ((QueryMemberContentBean) element).getItemDescription();
			if (tempString.length()>15) {
				holder.treeSinglDescription.setText(tempString.substring(0, 15)+"...");
			}else{
				holder.treeSinglDescription.setText(tempString);
			}
			tempString = null;
			tempString2 = null;
			Date date = new Date(((QueryMemberContentBean) element).getItemDate() * 1000L);
			DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			holder.treeSinglDescDate.setText(dateFormat.format(date));
//			holder.treeSinglSpname.setText(((QueryMemberContentBean) element).getTreeName());
			/*字數過多切字*/
			if (((QueryMemberContentBean) element).getTreeName().length() > 4) {
				String s = (((QueryMemberContentBean) element).getTreeName()).substring(0, 4)+"...";
				holder.treeSinglSpname.setText(s);
			}else{
				holder.treeSinglSpname.setText(((QueryMemberContentBean) element).getTreeName());
			}
			return convertView;
		}
		
		private class ViewHolder {
			TextView treeSinglName;
			TextView treeSinglSpname;
			TextView treeSinglDescription;
			TextView treeSinglDescDate;
		}

	}
	
}
